package com.haixin.test.config;

import com.haixin.test.task.ThreeTask;
import com.haixin.test.task.TwoTask;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.text.SimpleDateFormat;

/**
 * @author zjs
 * @description
 * @Date 2022-4-5
 */
@Configuration
public class QuartzConfig {

    @Bean
    public JobDetail testQuartz(){
        return JobBuilder.newJob(TwoTask.class).withIdentity("twoTask").storeDurably().build();
    }

    @Bean
    public Trigger testQuartzTrigger(){
        SimpleScheduleBuilder simpleScheduleBuilder = SimpleScheduleBuilder.simpleSchedule()
                .withIntervalInSeconds(5)
                .repeatForever();
        return TriggerBuilder.newTrigger().forJob(testQuartz())
                .withIdentity("twoTask")
                .withSchedule(simpleScheduleBuilder)
                .build();
    }

    @Bean
    public JobDetail ThreeQuartz(){
        return JobBuilder.newJob(ThreeTask.class).withIdentity("ThreeTask").storeDurably().build();
    }

    @Bean
    public Trigger ThreeQuartzTrigger(){
        return TriggerBuilder.newTrigger().forJob(ThreeQuartz())
                .withIdentity("ThreeTask")
                .withSchedule(CronScheduleBuilder.cronSchedule("*/5 * * * * ?"))
                .build();
    }

}
